import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { StrengthenAddInfo } from "./info/StrengthenAddInfo";
import { StringHelper } from "../../../com/gengine/utils/StringHelper";
import { EquipTargetType } from "./info/EquipTargetType";
import { PetTalentAddInfo } from "./info/PetTalentAddInfo";
import { FashionJewelTargetData } from "../view/fashionBox/fashionJewel/FashionJewelTargetData";
import { CareerUtil } from "../view/common/util/CareerUtil";
type int = number;
//class StrengthAddConfig
    
    export  class StrengthAddConfig
    {
        constructor()
        {
            
            this._map = new Map<any, any> /* flash.utils.Dictionary */();
            this._petAddInfoArray = [];
            this._mapAttribute = new Map<any, any> /* flash.utils.Dictionary */();
            this.fashionJewelTargetArr = [];
            this._fashionJewelDic = new Map<any, any> /* flash.utils.Dictionary */();
            this.fashionFlyWingTargetArr = [];
            this._fashionFlyWingDic = new Map<any, any> /* flash.utils.Dictionary */();
            if (StrengthAddConfig._instance != null) 
            {
                throw new Error(" StrengthAddConfig 单例 ");
            }
            StrengthAddConfig._instance = this;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_strengthen_add.json");
            this.write(loc1);
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new StrengthenAddInfo();
                loc1.id = loc2.id;
                loc1.type = loc2.type;
                loc1.level = loc2.level;
                loc1.amount = loc2.amount;
                loc1.career = loc2.career;
                loc1.attribute = StringHelper.getString(loc2.attribute);
                loc1.initParse();
                this._map[loc1.type + "_" + loc1.career + "_" + loc1.level + "_" + loc1.amount] = loc1;
                if (loc1.type == EquipTargetType.PetTalentTarget) 
                {
                    this._petAddInfoArray.push(loc1);
                }
                if (loc1.type == EquipTargetType.FashionJewelTarget) 
                {
                    this.fashionJewelTargetArr.push(loc1.level);
                    this._fashionJewelDic[loc1.level] = loc1.attribute;
                }
                if (loc1.type != EquipTargetType.FashionFlyWingTarget) 
                {
                    continue;
                }
                this.fashionFlyWingTargetArr.push(loc1.level);
                this._fashionFlyWingDic[loc1.level] = loc1.attribute;
            }
            this._petAddInfoArray.sortOn("level");
            this.fashionJewelTargetArr.sort(Array.NUMERIC);
            this.fashionFlyWingTargetArr.sort(Array.NUMERIC);
            return;
        }

        public getStrengthenAddInfo(arg1: int, arg2: int, arg3: int, arg4: int=-1): StrengthenAddInfo
        {
            var loc1=null;
            var loc2=0;
            var loc3=this._map;
            for(loc1 of loc3) 
            {
                if (!(loc1.type == arg1 && loc1.career & arg2 && loc1.level == arg3 && (arg4 == -1 || arg4 == loc1.amount))) 
                {
                    continue;
                }
                return loc1;
            }
            return null;
        }

        public getLowestAddInfo(arg1: int, arg2: int): StrengthenAddInfo
        {
            var loc1=null;
            var loc3=null;
            var loc2=this.getAddInfoArray(arg1, arg2);
            var loc4=0;
            var loc5=loc2;
            for(loc3 of loc5) 
            {
                if (!(loc1 == null || loc3.level < loc1.level && loc3.amount < loc1.amount)) 
                {
                    continue;
                }
                loc1 = loc3;
            }
            return loc1;
        }

        public getAddInfoArray(arg1: int, arg2: int): Array<any>
        {
            var loc2=null;
            var loc1=[];
            var loc3=0;
            var loc4=this._map;
            for(loc2 of loc4) 
            {
                if (!(loc2.type == arg1 && loc2.career & arg2)) 
                {
                    continue;
                }
                loc1.push(loc2);
            }
            loc1.sortOn(["level", "amount"], [Array.NUMERIC, Array.NUMERIC]);
            return loc1;
        }

        public getPetTalentAddInfo(arg1: int, arg2: int): PetTalentAddInfo
        {
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc1=this.getAddInfoArray(EquipTargetType.PetTalentTarget, arg1);
            var loc2=new PetTalentAddInfo();
            var loc6=0;
            while (loc6 < loc1.length) 
            {
                if ((loc3 = loc1[loc6]).career & arg1) 
                {
                    if (arg2 < loc3.level) 
                    {
                        if (loc1[(loc6 - 1)]) 
                        {
                            loc4 = loc1[(loc6 - 1)];
                            loc5 = loc3;
                            break;
                        }
                        else 
                        {
                            loc5 = loc3;
                            break;
                        }
                    }
                    else if (arg2 != loc3.level) 
                    {
                        if (loc1[loc6 + 1] == null) 
                        {
                            loc4 = loc3;
                            break;
                        }
                    }
                    else 
                    {
                        loc4 = loc3;
                        if (loc1[loc6 + 1]) 
                        {
                            loc5 = loc1[loc6 + 1];
                        }
                        break;
                    }
                }
                ++loc6;
            }
            loc2.currentAddInfo = loc4;
            loc2.nextAddInfo = loc5;
            return loc2;
        }

        public getAttributeInfo(arg1: StrengthenAddInfo): Array<any>
        {
            var loc6=null;
            var loc7=null;
            if (arg1 == null) 
            {
                return [];
            }
            var loc1=arg1.type;
            var loc2=arg1.career;
            var loc3=arg1.level;
            var loc4=arg1.amount;
            var loc5=loc1 + "_" + loc2 + "_" + loc3 + "_" + loc4;
            if (this._mapAttribute[loc5]) 
            {
                loc6 = this._mapAttribute[loc5];
            }
            else 
            {
                arg1.initParse();
                loc6 = arg1.addInfoArray.concat();
                var loc8=0;
                var loc9=this._map;
                for(loc7 of loc9) 
                {
                    if (!(loc7.type == loc1 && loc7.career == loc2)) 
                    {
                        continue;
                    }
                    if (!(loc7.level < loc3 || loc7.level == loc3 && loc7.amount < loc4)) 
                    {
                        continue;
                    }
                    loc7.initParse();
                    loc6 = this.addAttributes(loc6, loc7.addInfoArray);
                }
                this._mapAttribute[loc5] = loc6;
            }
            return loc6;
        }

        /* internal  */addAttributes(arg1: Array<any>, arg2: Array<any>): Array<any>
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=0;
            var loc5=0;
            var loc6=0;
            var loc9=0;
            var loc7=arg2.concat();
            var loc8=0;
            while (loc8 < arg1.length) 
            {
                loc1 = arg1[loc8];
                loc9 = 0;
                while (loc9 < loc7.length) 
                {
                    loc2 = loc7[loc9];
                    if (loc1["name"] == loc2["name"]) 
                    {
                        loc3 = parseInt(loc1["value"]);
                        loc4 = parseInt(loc2["value"]);
                        loc5 = loc3 / 1000000;
                        loc6 = loc4 / 1000000;
                        loc3 = loc3 % 1000000;
                        loc4 = loc4 % 1000000;
                        if (loc5 + loc6 > 0) 
                        {
                            loc1["value"] = loc5 + loc6 + "%\t+" + (loc3 + loc4);
                        }
                        else 
                        {
                            loc1["value"] = "+" + (loc3 + loc4);
                        }
                        loc7.splice(loc9, 1);
                    }
                    ++loc9;
                }
                ++loc8;
            }
            arg1.concat(loc7);
            return arg1;
        }

        public getFashionJewelTargetDic(arg1: int, arg2: int): FashionJewelTargetData
        {
            var loc8=0;
            var loc10=undefined;
            var loc11=0;
            var loc1=this.fashionJewelTargetArr.indexOf(arg1);
            var loc2=new Map<any, any> /* flash.utils.Dictionary */();
            var loc3="";
            var loc4=[];
            var loc5="";
            var loc6=[];
            var loc7=new FashionJewelTargetData();
            var loc9=0;
            while (loc9 < loc1 + 1) 
            {
                loc8 = this.fashionJewelTargetArr[loc9];
                loc4 = (loc3 = this._fashionJewelDic[loc8]).split("#");
                loc11 = 0;
                while (loc11 < loc4.length) 
                {
                    if (!((loc5 = loc4[loc11] as string) == null) && !(loc5 == "")) 
                    {
                        loc6 = loc5.split(",");
                        if (loc2[parseInt(loc6[0])]) 
                        {
                            loc2[parseInt(loc6[0])] = loc2[parseInt(loc6[0])] + parseInt(loc6[1]);
                        }
                        else 
                        {
                            loc2[parseInt(loc6[0])] = parseInt(loc6[1]);
                        }
                    }
                    ++loc11;
                }
                ++loc9;
            }
            var loc12=0;
            var loc13=loc2;
            for (loc10 in loc13) 
            {
                if (loc10 == "8" || loc10 == "12") 
                {
                    if (CareerUtil.isPhysicalCareer(arg2)) 
                    {
                        loc7.attArr.push(loc10);
                        loc7.arrNum[loc10] = loc2[loc10];
                    }
                    continue;
                }
                if (loc10 == "9" || loc10 == "13") 
                {
                    if (CareerUtil.isMagicCareer(arg2)) 
                    {
                        loc7.attArr.push(loc10);
                        loc7.arrNum[loc10] = loc2[loc10];
                    }
                    continue;
                }
                loc7.attArr.push(loc10);
                loc7.arrNum[loc10] = loc2[loc10];
            }
            loc7.attArr.sortOn(Array.NUMERIC);
            return loc7;
        }

        public getFashionFlyWingTargetDic(arg1: int, arg2: int): FashionJewelTargetData
        {
            var loc8=0;
            var loc10=undefined;
            var loc11=0;
            var loc1=this.fashionFlyWingTargetArr.indexOf(arg1);
            var loc2=new Map<any, any> /* flash.utils.Dictionary */();
            var loc3="";
            var loc4=[];
            var loc5="";
            var loc6=[];
            var loc7=new FashionJewelTargetData();
            var loc9=0;
            while (loc9 < loc1 + 1) 
            {
                loc8 = this.fashionFlyWingTargetArr[loc9];
                loc4 = (loc3 = this._fashionFlyWingDic[loc8]).split("#");
                loc11 = 0;
                while (loc11 < loc4.length) 
                {
                    if (!((loc5 = loc4[loc11] as string) == null) && !(loc5 == "")) 
                    {
                        loc6 = loc5.split(",");
                        if (loc2[parseInt(loc6[0])]) 
                        {
                            loc2[parseInt(loc6[0])] = loc2[parseInt(loc6[0])] + parseInt(loc6[1]);
                        }
                        else 
                        {
                            loc2[parseInt(loc6[0])] = parseInt(loc6[1]);
                        }
                    }
                    ++loc11;
                }
                ++loc9;
            }
            var loc12=0;
            var loc13=loc2;
            for (loc10 in loc13) 
            {
                if (loc10 == "8" || loc10 == "12") 
                {
                    if (CareerUtil.isPhysicalCareer(arg2)) 
                    {
                        loc7.attArr.push(loc10);
                        loc7.arrNum[loc10] = loc2[loc10];
                    }
                    continue;
                }
                if (loc10 == "9" || loc10 == "13") 
                {
                    if (CareerUtil.isMagicCareer(arg2)) 
                    {
                        loc7.attArr.push(loc10);
                        loc7.arrNum[loc10] = loc2[loc10];
                    }
                    continue;
                }
                loc7.attArr.push(loc10);
                loc7.arrNum[loc10] = loc2[loc10];
            }
            loc7.attArr.sortOn(Array.NUMERIC);
            return loc7;
        }

        public static get instance(): StrengthAddConfig
        {
            if (StrengthAddConfig._instance == null) 
            {
                StrengthAddConfig._instance = new StrengthAddConfig();
            }
            return StrengthAddConfig._instance;
        }

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_petAddInfoArray: Array<any>;

        /* internal */ /* var */_mapAttribute: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_lowLevel: int=5;

        /* internal */ /* var */_lowLevelJewel: int=4;

        public /* var */fashionJewelTargetArr: Array<any>;

        /* internal */ /* var */_fashionJewelDic: Map<any, any> /* flash.utils.Dictionary */;

        public /* var */fashionFlyWingTargetArr: Array<any>;

        /* internal */ /* var */_fashionFlyWingDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: StrengthAddConfig;
    }
